package com.hiray.demos

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration
import kotlinx.android.synthetic.main.activity_index.*

abstract class IndexActivity : AppCompatActivity() ,ItemAdapter.OnItemClickListener{

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_index)
        val itemAdapter = ItemAdapter(getData(), this)
        itemAdapter.cornerMarker = true
        recyclerview.adapter = itemAdapter
        recyclerview.addItemDecoration(HorizontalDividerItemDecoration.Builder(this)
                .colorResId(R.color.divider_light)
                .size(5)
                .build())
    }

    abstract fun getData():List<String>

    abstract fun handleItemClick(index:Int,title:String)

    override fun onItemClick(position: Int) {
        handleItemClick(index = position, title = getData()[position])
    }
}
